import java.io.File;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JList;
import javax.swing.JPanel;

public class FilesList extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	List<File> flist;
	List<String> fnames;
	JList<Object> drawableList;

	public FilesList(String dir) {
		super();
		flist = new LinkedList<File>();
		fnames = new LinkedList<String>();
		this.setVisible(true);
		this.loadDir(dir);
	}

	public void loadDir(String dir) {
		File f = new File(dir);
		if (f.isDirectory()) {

			File[] l = f.listFiles();

			System.out.println("Liste de fichiers : " + l);
			for (int i = 0; i < l.length; i++) {
				if (l[i].getName().charAt(0) != '.') {
					System.out.println(l[i] + " is a good file");
					if (l[i].isDirectory()) {
						System.out.println("And is a directory");
						flist.add(l[i]);
						fnames.add(l[i].getName());
					} else {
						System.out.println("And isn't a directory");
					}
				}
			}
			drawableList = new JList<Object>(fnames.toArray());
			this.add(drawableList);
		}
	}
}
